package com.xxx.controller;

import com.xxx.entity.Product;
import com.xxx.vos.CollectionVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @author blijojo
 * @date 2021/5/22
 */
@RestController
@Slf4j
public class ProductController {

    @Value("${server.port}")
    private int port;

    @GetMapping("/product/test")
    public String product() {
        log.info("调用product服务,服务端口:{}", port);
        return "product ok!" + port;
    }

    @GetMapping("/product/list")
    public String list() {
        log.info("调用list服务,服务端口:{}", port);
        return "list ok!" + port;
    }

    @GetMapping("/product/test1")
    public String test1(String name, String age) {
        log.info("name:{}   age:{}", name, age);
        return "product.test1 ok,服务端口:" + port;
    }


    @GetMapping("/product/test2/{name}/{age}")
    public String test2(@PathVariable("name") String name, @PathVariable("age") String age) {
        log.info("name:{}   age:{}", name, age);
        return "product.test2 ok,服务端口:" + port;
    }

    @PostMapping("/product/test3")
    public String test3(@RequestBody Product product) {
        log.info("product:{}", product);
        return "product.test3 ok,服务端口:" + port;
    }

    @GetMapping("/product/test4")
    public String test4(@RequestParam("ids") String[] ids) {
        log.info("ids:{}", Arrays.toString(ids));
        return "product.test4 ok,服务端口:" + port;
    }

    @GetMapping("/product/test5")
    public String test5(CollectionVO vo) {
        vo.getIds().forEach(id -> log.info("id:{}", id));
        return "product.test5 ok,服务端口:" + port;
    }

}
